package br.org.bertol.mestrado.engine;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.concurrent.CountDownLatch;

import br.org.bertol.mestrado.Buscador;
import br.org.bertol.mestrado.Verify;

public abstract class SearchEngine extends Thread {
    // 1 starter para todos as her�sticas
    protected CountDownLatch startHeuristic = new CountDownLatch(1);

    // 5 contadores de t�rmino de heuristica
    // para cada resultado conseguido no greedy
    protected CountDownLatch doneHeuristic;

    protected CountDownLatch startSystem;

    protected CountDownLatch stopSystem;

    protected String         systemID;

    protected String         storePath;

    protected int            numIteracoes;

    protected Verify         verify;

    final EnumSet<Objective> typeEvaluation;

    public SearchEngine(final CountDownLatch startS,
        final CountDownLatch stopS, final int numEval,
        final Objective[] objectives, final String storeP, final String sID) {
        super();

        // inicia inst�ncia do verificador
        verify = new Verify(objectives, storeP, sID);

        typeEvaluation = EnumSet.noneOf(Objective.class);

        typeEvaluation.addAll(Arrays.asList(verify.getObjectives()));

        setName("Sistema " + sID + " | Tipo avalia��o " + typeEvaluation
                + " | N� de itera��es " + numEval);

        startSystem = startS;

        stopSystem = stopS;

        systemID = sID;

        storePath = storeP;

        numIteracoes = numEval;

        Buscador.randomSolution.setVerify(verify);
    }

    public abstract void writeToFile(PrintWriter outFile);
}
